package br.unb.statistic.function;

import br.unb.utils.Resource;

public class HaarWavelet {

    public static double[] upScale(double[][] values) throws IllegalArgumentException {
        if (values.length != 2) {
            throw new IllegalArgumentException(Resource.getString("INVALID_ARGUMENT"));
        }
        int size = values[0].length;
        double[] result = new double[2 * size];
        for (int k = 0; k < size; k++) {
            result[2 * k] = (1 / Math.sqrt(2)) * (values[0][k] + values[1][k]);
            result[2 * k + 1] = (1 / Math.sqrt(2)) * (values[0][k] - values[1][k]);
        }
        return result;
    }

    public static double[][] downScale(double[] values) {
        int size = values.length;
        double[][] result = new double[2][size];
        for (int k = 0; k < size; k++) {
            result[0][k] = (1 / Math.sqrt(2)) * (values[2 * k] + values[2 * k + 1]);
            result[1][k] = (1 / Math.sqrt(2)) * (values[2 * k] - values[2 * k + 1]);
        }
        return result;
    }
}
